<!doctype html public "-//W3C//DTD HTML 4.0 Frameset//EN""http://www.w3.org/TR/REC-html40/frameset.dtd">
<html>
<head>
<title>
 Overview
</title>
<link rel ="stylesheet" type="text/css" href="../stylesheet.css" title="Style">
<script>
function asd() {
	
		parent.document.title="Cloneable.jsc Overview";
	
}
</script>
</head>
<body bgcolor="white" onload="asd();">

<!-- ========== START OF NAVBAR ========== -->
<a name="navbar_top"><!-- --></a>
<table border="0" width="100%" cellpadding="1" cellspacing="0">
<tr>
<td colspan=2 bgcolor="#EEEEFF" class="NavBarCell1">
<a name="navbar_top_firstrow"><!-- --></a>
<table border="0" cellpadding="0" cellspacing="3">
  <tr align="center" valign="top">
  
  
  <td bgcolor="#EEEEFF" class="NavBarCell1">    <a href="../overview-summary.html"><font class="NavBarFont1"><b>Overview</b></font></a>&nbsp;</td>
  <td bgcolor="#FFFFFF" class="NavBarCell1Rev">	&nbsp;<font class="NavBarFont1Rev"><b>File</b></font>&nbsp;</td>
  

  <td bgcolor="#FFFFFF" class="NavBarCell1"> 	<font class="NavBarFont1">Class</font>&nbsp;</td>
  <td bgcolor="#EEEEFF" class="NavBarCell1">    <a href="../overview-tree.html"><font class="NavBarFont1"><b>Tree</b></font></a>&nbsp;</td>
  <td bgcolor="#EEEEFF" class="NavBarCell1">    <a href="../index-all.html"--><font class="NavBarFont1"><b>Index</b></font></a>&nbsp;</td>
  <td bgcolor="#EEEEFF" class="NavBarCell1">    <a href="../help-doc.html"><font class="NavBarFont1"><b>Help</b></font></a>&nbsp;</td>
  </tr>
</table>
</td>
<td bgcolor="#EEEEFF" align="right" valign="top">
<em>
<b></b></em>
</td>
</tr>

<tr>
<td bgcolor="white" class="NavBarCell2"><font size="-2">
&nbsp;PREV&nbsp;
&nbsp;NEXT</font></td>
<td bgcolor="white" class="NavBarCell2"><font size="-2">
  <a href="../index.html" target="_top"><b>FRAMES</b></a>  &nbsp;
&nbsp;<a href="../overview-summary.html" target="_top"><b>NO FRAMES</b></a>
&nbsp;&nbsp;
<script>
  <!--
  if(window==top) {
    document.writeln('<A HREF="allclasses-noframe.html" TARGET=""><B>All Classes</B></A>');
  }
  //-->
</script>
<noscript>
<a href="../allclasses-noframe.html" target=""><b>All Classes</b></a>
</noscript>
</font></td>
</tr>
</table>
<!-- =========== END OF NAVBAR =========== -->

<hr>
<center>
	
	   <h2>Cloneable.jsc</h2>
	
</center>

	


<h4>Summary</h4>
<p>
	
		js.lang.Cloneable class http://jsvm.homolo.com/jsvm2.0/docs/api/
 <BR/><BR/><B>Version: </B>2.01, 10/23/05
 <BR/><BR/><B>Author:</B> Wan Changhua
 <BR/>
	
</p>

<hr>


    <table border="1" cellpadding="3" cellspacing="0" width="100%">
    <tr bgcolor="#CCCCFF" class="TableHeadingColor">
    <td colspan=2><font size="+2">
    
        <b>Class Summary</b>
    
    </font></td>
    </tr>
    
    <tr bgcolor="white" class="TableRowColor">
    <td width="15%"><b><a href="Cloneable.html">js.lang.Cloneable</a></b></td>
    <td>js.lang.Cloneable is the base class for all can be cloned class.</td>
    </tr>
    
    </table>
    <hr/> 


<!-- ========== METHOD SUMMARY =========== -->

<!-- ========== END METHOD SUMMARY =========== -->


        <pre class="sourceview"># language: jsvm2

<span class="comment">/**
 * <span class="attrib">@fileoverview</span> js.lang.Cloneable class http://jsvm.homolo.com/jsvm2.0/docs/api/
 * <span class="attrib">@file</span>		Cloneable.jsc
 * <span class="attrib">@author</span>	Wan Changhua
 * <span class="attrib">@version</span>	2.01, 10/23/05
 * <span class="attrib">@since</span>		JSVM2.0
 */</span>

package js.lang;

import js.lang.JObject;
import js.lang.ArgumentException;


<span class="comment">/**
 * A class extends the &lt;code&gt;js.lang.Cloneable&lt;/code&gt; class to 
 * indicate to the clone() method that it 
 * is legal for that method to make a 
 * field-for-field copy of instances of that class. 
 * <span class="attrib">@author</span>	Wan Changhua
 * <span class="attrib">@version</span>	2.01, 10/23/05
 * <span class="attrib">@extends</span> JObject
 * <span class="attrib">@class</span> js.lang.Cloneable is the base class for all can be cloned class.
 * <span class="attrib">@constructor</span>
 * <span class="attrib">@throws</span> ArgumentException if param error
 * <span class="attrib">@return</span> A new Cloneable
 * #see JObject js.lang.JObject is the base class for this
 */</span>
<span class="reserved">function</span> Cloneable ()
{
}

<span class="comment">/**
 * Creates and returns a copy of this object.  The precise meaning 
 * of "copy" may depend on the class of the object. The general 
 * intent is that, for any object x, the expression:
 * The method clone for class Object performs a 
 * specific cloning operation. 
 * The class does not itself extends the class 
 * Cloneable, so calling the clone method on an object 
 * whose class is Object will result in throwing an
 * exception at run time.
 *
 * <span class="attrib">@exception</span>  ArgumentException  if the object's class does not
 *               support the &lt;code&gt;Cloneable&lt;/code&gt; class. Subclasses
 *               that override the &lt;code&gt;clone&lt;/code&gt; method can also
 *               throw this ArgumentException to indicate that an instance cannot
 *               be cloned.
 * <span class="attrib">@return</span> a clone of this instance.
 * <span class="attrib">@type</span> Object
 */</span>
Cloneable.<span class="reserved">prototype</span>.clone = <span class="reserved">function</span> ()
{
	var co = <span class="reserved">this</span>.getClass().newInstance();
	<span class="reserved">for</span> (var p in <span class="reserved">this</span>)
	{
		var v = <span class="reserved">this</span>[p];
		<span class="reserved">if</span> (typeof(v) == <span class="literal">"function"</span>)
		{
			continue;
		}
		co[p] = v;
	}
	<span class="reserved">return</span> co;
}

<span class="comment">/**
 * Creates and returns a copy of this parameter.  
 * <span class="attrib">@param</span> {Object} obj an object
 * <span class="attrib">@exception</span>  ArgumentException  if the parameter can not been cloned.
 * <span class="attrib">@return</span> a clone of this parameter.
 * <span class="attrib">@type</span> Object
 */</span>
Cloneable.cloneObject = <span class="reserved">function</span> (o)
{
	<span class="reserved">if</span> (o instanceof Cloneable)
	{
		<span class="reserved">return</span> o.clone();
	}
	var type = typeof(o);
	switch (type)
	{
		case <span class="literal">"undefined"</span> :
		case <span class="literal">"boolean"</span> : 
		case <span class="literal">"string"</span> : 
		case <span class="literal">"number"</span> : <span class="reserved">return</span> o;
		case <span class="literal">"function"</span> : <span class="reserved">return</span> o; <span class="comment">//TODO</span>
		case <span class="literal">"object"</span> : 
			<span class="reserved">if</span> (o == null)
			{
				<span class="reserved">return</span> null;
			}
			<span class="reserved">if</span> (o instanceof Date)
			{
				<span class="reserved">return</span> new Date(o.getTime());
			}
			<span class="reserved">if</span> (o instanceof Number)
			{
				<span class="reserved">return</span> new Number(o.valueOf());
			}
			<span class="reserved">if</span> (o instanceof Boolean)
			{
				<span class="reserved">return</span> new Boolean(o.valueOf());
			}
			<span class="reserved">if</span> (o instanceof Error)
			{
				<span class="reserved">return</span> new Error(o.number, o.message);
			}
			<span class="reserved">if</span> (o instanceof Array)
			{
				<span class="reserved">return</span> o.concat([]);
			}
			<span class="reserved">if</span> (o instanceof JObject)
			{
				throw new ArgumentException(Cloneable.getName()
					+ <span class="literal">".cloneObject(o) error, coundn't clone a '"</span>
					+ o.getClass().getName()
					+ <span class="literal">"' instance."</span>);
			}
			<span class="reserved">if</span> (o instanceof Object)
			{
				var co = {};
				<span class="reserved">for</span> (var k in o)
				{
					co[k] = o[k];
				}
				<span class="reserved">return</span> co;
			}
		default : break;
	}
	throw new ArgumentException(Cloneable.getName()
		+ <span class="literal">".cloneObject(o) error, [type: "</span> 
		+ type + <span class="literal">"]"</span>);
}
</pre>
	<hr>



<!-- ========== START OF NAVBAR ========== -->
<a name="navbar_top"><!-- --></a>
<table border="0" width="100%" cellpadding="1" cellspacing="0">
<tr>
<td colspan=2 bgcolor="#EEEEFF" class="NavBarCell1">
<a name="navbar_top_firstrow"><!-- --></a>
<table border="0" cellpadding="0" cellspacing="3">
  <tr align="center" valign="top">
  
  
  <td bgcolor="#EEEEFF" class="NavBarCell1">    <a href="../overview-summary.html"><font class="NavBarFont1"><b>Overview</b></font></a>&nbsp;</td>
  <td bgcolor="#FFFFFF" class="NavBarCell1Rev">	&nbsp;<font class="NavBarFont1Rev"><b>File</b></font>&nbsp;</td>
  

  <td bgcolor="#FFFFFF" class="NavBarCell1"> <font class="NavBarFont1">Class</font>&nbsp;</td>
  <td bgcolor="#EEEEFF" class="NavBarCell1">    <a href="../overview-tree.html"><font class="NavBarFont1"><b>Tree</b></font></a>&nbsp;</td>
  <td bgcolor="#EEEEFF" class="NavBarCell1">    <a href="../index-all.html"--><font class="NavBarFont1"><b>Index</b></font></a>&nbsp;</td>
  <td bgcolor="#EEEEFF" class="NavBarCell1">    <a href="../help-doc.html"><font class="NavBarFont1"><b>Help</b></font></a>&nbsp;</td>
  </tr>
</table>
</td>
<td bgcolor="#EEEEFF" align="right" valign="top"><em>
<b></b></em>
</td>
</tr>

<tr>
<td bgcolor="white" class="NavBarCell2"><font size="-2">
&nbsp;PREV&nbsp;
&nbsp;NEXT</font></td>
<td bgcolor="white" class="NavBarCell2"><font size="-2">
  <a href="../index.html" target="_top"><b>FRAMES</b></a>  &nbsp;
&nbsp;<a href="../overview-summary.html" target="_top"><b>NO FRAMES</b></a>
&nbsp;&nbsp;
<script>
  <!--
  if(window==top) {
    document.writeln('<A HREF="allclasses-noframe.html" TARGET=""><B>All Classes</B></A>');
  }
  //-->
</script>
<noscript>
<a href="../allclasses-noframe.html" target=""><b>All Classes</b></a>
</noscript>
</font></td>
</tr>
</table>
<!-- =========== END OF NAVBAR =========== -->

<hr>
<font size="-1">

</font>
<div class="jsdoc_ctime">Documentation generated by <a href="http://jsdoc.sourceforge.net/" target="_parent">JSDoc</a> on Thu Nov 17 20:10:21 2005</div>
</body>
</html>
